package com.bana.fvs.app.util;

import android.app.Activity;
import android.content.res.Resources;
import android.text.TextUtils;

import com.bana.fvs.R;
import com.bana.fvs.app.enter.NewVersionBean;
import com.wei.commonlibrary.dialog.BaseDialog;
import com.wei.commonlibrary.dialog.TextDescDialog;
import com.wei.commonlibrary.dialog.VersionUpdateDialog;

/**
 * Created by ${wei} on 2017/5/25.
 */

public class DialogManager {
    /**
     * 版本更新的弹窗
     * Dialog
     *
     * @param newVersionBean
     */
    public static VersionUpdateDialog createUpdateDialog(final Activity activity,
                                                         final NewVersionBean newVersionBean, BaseDialog.OnDialogListener listener) {
        Resources resources = activity.getResources();
        String leftText = resources.getString(R.string.update);
        String rightText = null;
        if (TextUtils.equals("0", newVersionBean.getInstall())) {//是否强制安装 0.非强制（显示取消按钮） 1.强制
            rightText = resources.getString(R.string.cancel);
        }
        BaseDialog.Builder builder = new VersionUpdateDialog.Builder()
                .setContext(activity)
                .setContent(newVersionBean.getLog())
                .setIconDrawable(activity.getResources().getDrawable(R.mipmap.ic_launcher))
                .setVersionCode(newVersionBean.getVersion())
                .setVersionSize(String.valueOf(newVersionBean.getAppsize()))
                .setleftBtnText(leftText)
                .setRightBtnText(rightText);

        final VersionUpdateDialog updateDialog = (VersionUpdateDialog) builder.build();
        updateDialog.setOnDialogListener(listener);
        return updateDialog;
    }

    public static void showHintDialog(Activity activity) {
        TextDescDialog dialog = (TextDescDialog) new TextDescDialog.Builder()
                .setContext(activity)
                .setContent("请联系开发人员☺")
                .build();
        dialog.setOnDialogListener(new BaseDialog.OnDialogListener() {
            @Override
            public void rightClick(String text) {
                dialog.dismiss();
            }

            @Override
            public void leftClick() {
                dialog.dismiss();
                System.exit(0);
            }
        });
        dialog.show();
    }
}
